package com.tools.model.entity;

import com.tools.commons.base.BaseEntity;
import com.tools.commons.utils.IdGenerator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.Where;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;

/**
 * '用户表'
 *
 * @author wangminggen
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "t_users")
@Where(clause = "deleted = 0")
public class UserEntity extends BaseEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "inner_id", nullable = false, length = 20)
    private Long innerId;

    @Column(name = "phone", length = 11)
    private String phone;

    @Column(name = "user_id")
    private String userId;

    @Column(name = "is_doctor", length = 1)
    private boolean isDoctor;

    @Column(name = "status", length = 1)
    private Integer status;

    @PrePersist
    public void prePersist() {
        super.prePersist();
        if (this.userId == null) {
            this.userId = IdGenerator.uuid();
        }
    }
}
